package cn.jjxx.modules.screen.service.impl;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import cn.jjxx.core.common.service.impl.CommonServiceImpl;
import cn.jjxx.core.query.data.Page;
import cn.jjxx.core.query.data.PageImpl;
import cn.jjxx.core.query.data.Pageable;
import cn.jjxx.core.query.data.Queryable;
import cn.jjxx.core.query.parse.QueryToWrapper;
import cn.jjxx.modules.screen.mapper.BigScreenInfoMapper;
import cn.jjxx.modules.screen.entity.BigScreenInfo;
import cn.jjxx.modules.screen.service.IBigScreenInfoService;
import cn.jjxx.modules.screen.vo.IPage;
import cn.jjxx.modules.screen.vo.MPage;
import cn.jjxx.modules.screen.vo.QueryForm;
import cn.jjxx.modules.screen.vo.ScreenDto;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.mapper.Wrapper;

/**   
 * @Title: big_screen_info
 * @Description: big_screen_info
 * @author yx
 * @date 2022-05-07 09:39:56
 * @version V1.0   
 *
 */
@Transactional
@Service("bigScreenInfoService")
public class BigScreenInfoServiceImpl  extends CommonServiceImpl<BigScreenInfoMapper,BigScreenInfo> implements  IBigScreenInfoService {

	@Override
	public boolean insertBatch(List<BigScreenInfo> list) {
		if(list!=null&&list.size()>0){
			return baseMapper.insertBatch(list);
		}
		return true;
	}

	@Override
	public boolean updateBatch(List<BigScreenInfo> list) {
		if(list!=null&&list.size()>0){
			return baseMapper.updateBatch(list);
		}
		return true;
	}

	
	@Override
	public boolean insert(BigScreenInfo entity) {
		BigScreenInfo diskScreen = baseMapper.selectById(entity.getId());
		if (diskScreen == null) {
			entity.setEnable(1);
			baseMapper.insert(entity);
		} else {
			entity.setEnable(diskScreen.getEnable());
			this.baseMapper.updateById(entity);
		}
		return true;
	}
	@Override
	@Transactional
	public void copyScreenInfo(String screenId) {
		BigScreenInfo screen = this.baseMapper.selectById(screenId);
		screen.setId(UUID.randomUUID().toString());
		screen.setEnable(1);
		screen.setRemark("复制模板");
		screen.setName(screen.getName());
		screen.setCreateTime(new Date());
		this.baseMapper.insert(screen);
	}
	
	@Override
	public Page<BigScreenInfo> list(String pages,Queryable queryable, Wrapper<BigScreenInfo> wrapper) {
		QueryToWrapper<BigScreenInfo> queryToWrapper = new QueryToWrapper<BigScreenInfo>();
		queryToWrapper.parseCondition(wrapper, queryable);
		// 排序问题
		queryToWrapper.parseSort(wrapper, queryable);
		Pageable pageable = queryable.getPageable(); 
		com.baomidou.mybatisplus.plugins.Page<BigScreenInfo> page = new com.baomidou.mybatisplus.plugins.Page<BigScreenInfo>(
				Integer.parseInt(pages), pageable.getPageSize());
		com.baomidou.mybatisplus.plugins.Page<BigScreenInfo> content =  selectPage(page, wrapper);
		return new PageImpl<BigScreenInfo>(content.getRecords(), queryable.getPageable(), content.getTotal());
	}
}
